<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="编码">
              <a-input placeholder="请输入编码" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="开始时间">
              <a-date-picker
                v-model="queryParam.startTime"
                :disabled-date="disabledStartDate"
                show-time
                placeholder="请选择开始时间"
                @change="showStartDate"
                @openChange="handleStartOpenChange"
                style="width:100%;"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="结束时间">
              <a-date-picker
                v-model="queryParam.endTime"
                :disabled-date="disabledEndDate"
                show-time
                placeholder="请选择结束时间"
                :open="endOpen"
                @change="showEndDate"
                @openChange="handleEndOpenChange"
                style="width:100%;"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('外部接口请求日志','1')">导出</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">详情</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        <template slot="indata" slot-scope="text,record">
          <div :title="text" style="width: 220px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{text}}</div>
        </template>
        <template slot="outdata" slot-scope="text,record">
          <div :title="text" style="width: 220px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{text}}</div>
        </template>
        <template slot="url" slot-scope="text,record">
          <div :title="text" style="width: 220px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{text}}</div>
        </template>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <httpLog-modal ref="modalForm" @ok="modalFormOk"></httpLog-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import HttpLogModal from './modules/HttpLogModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'

  export default {
    name: 'HttpLogList',
    mixins: [JeecgListMixin],
    components: {
      HttpLogModal
    },
    data() {
      return {
        description: '接口请求日志管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '编码',
            align: 'center',
            dataIndex: 'code'
          },
          {
            title: '请求地址',
            align: 'center',
            dataIndex: 'url',
            width: 230,
            scopedSlots: { customRender: 'url' }
          },
          {
            title: '请求数据',
            align: 'center',
            dataIndex: 'indata',
            width: 230,
            scopedSlots: { customRender: 'indata' }
          },
          {
            title: '返回结果',
            align: 'center',
            dataIndex: 'outdata',
            width: 230,
            scopedSlots: { customRender: 'outdata' }
          },
          {
            title: '请求响应码',
            align: 'center',
            dataIndex: 'httpCode'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        endOpen: false,
        startTime: null,
        endTime: null,
        url: {
          list: '/tpsoft/httpLog/list',
          delete: '/tpsoft/httpLog/delete',
          deleteBatch: '/tpsoft/httpLog/deleteBatch',
          exportXlsUrl: 'tpsoft/httpLog/exportXls'
        }
      }
    },
    computed: {},
    methods: {
      disabledStartDate(startValue) {
        const endValue = this.endTime
        if (!startValue || !endValue) {
          return false
        }
        return startValue.valueOf() > endValue.valueOf()
      },
      disabledEndDate(endValue) {
        const startValue = this.startTime
        if (!endValue || !startValue) {
          return false
        }
        return startValue.valueOf() >= endValue.valueOf()
      },
      handleStartOpenChange(open) {
        if (!open) {
          this.endOpen = true
        }
      },
      handleEndOpenChange(open) {
        this.endOpen = open
      },
      showStartDate: function(time, timeString) {
        this.queryParam.startTime = timeString
        this.startTime = time
      },
      showEndDate: function(time, timeString) {
        this.queryParam.endTime = timeString
        this.endTime = time
      }
    }
  }
</script>